﻿namespace _04.PersonExercise
{
    using System;

    public class Person
    {
        private byte? age;
        private string name;

        public Person(string name)
            : this(name, null)
        {
        }

        public Person(string name, byte? age)
        {
            this.Name = name;
            this.Age = age;
        }

        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    throw new ArgumentException("Name must not be empty!");
                }
                else if (value.Length < 3)
                {
                    throw new ArgumentOutOfRangeException("Name must be at least 3 symbols!");
                }

                this.name = value;
            }
        }

        public byte? Age
        {
            get
            {
                return this.age;
            }

            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("Age must be positive number!");
                }

                this.age = value;
            }
        }

        public override string ToString()
        {
            return string.Format("Name: {0}, Age: {1}", this.Name, this.Age.HasValue ? this.Age.ToString(): "Unknown");
        }
    }
}